package com.an.utils;

import java.util.Random;
import java.util.Scanner;

/**
 * @author Li
 * @Date 2023/4/8 16:23
 */
public class SumTool {

    /**
     * 得到一个size大小的随机整数数组
     * @param size
     * @return
     */
    public static int[] getArray(int size) {
        int[] array = new int[size];
        Random random = new Random();
        for (int i = 0; i <array.length ; i++) {
            array[i] = random.nextInt(size);
        }
        printArray(array);
        return array;
    }

    /**
     * 遍历数组，打印出数组
     * @param array
     */
    public static void printArray(int[] array) {
        System.out.print("[");
        for (int i = 0; i < array.length; i++) {
            if (i==array.length-1){
                System.out.println(array[i]+"]");
            }else {
                System.out.print(array[i]+",");
            }
        }
    }

    /**
     * 键盘输入一个数整数
     * @param str
     * @return
     */
   public static int getIntoNum(String str) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入"+str+"值");
        return scanner.nextInt();
    }

    /**
     * 求数组的和
     * @param array
     * @return
     */
    public static int SumArray(int[] array) {
        int sum = 0;
        for (int i = 0; i <array.length ; i++) {
            sum+=array[i];
        }
         return sum;
    }

    /**
     * 求数组的最大值
     */

    public static int getMax(int[] array) {
        int max = array[0];
        for (int i = 0; i <array.length ; i++) {
           if (max<array[i]){
               max = array[i];
           }
        }
return max;
    }

    /**
     * 求数组的最小值
     */

    public static int getMin(int[] array) {
        int min = array[0];
        for (int i = 0; i <array.length ; i++) {
            if (min>array[i]){
                min = array[i];
            }
        }
        return min;
    }

    /**
     * 求数组的平均值
     */

    public static int getAverage(int[] array) {
        int average = 0;
        int sum = 0;
        for (int i = 0; i <array.length ; i++) {
            sum+=array[i];
            average = sum/array.length;
        }
        return average;
    }
    /**
     * 得到一个size大小的随机整数数组
     * @param size
     * @return
     */
    public static int[] getArray2(int size ,int max,int min) {
        int[] array = new int[size];
        Random random = new Random();
        for (int i = 0; i <array.length ; i++) {
            array[i] = random.nextInt(max-min)+min;
        }
        printArray(array);
        return array;
    }

}
